package Demo1;

class Animal {
    public String name;
    public int age;
    public String color;

//    static {
//        System.out.println("Animal的静态代码块！");
//    }
//
//    {
//        System.out.println("Animal的非静态代码块！");
//    }
    public Animal(String name) {
        this.name = name;
//        System.out.println("Animal(String)");
    }
    public void eat() {
        System.out.println(this.name + "正在吃饭！----Animal");
    }
}
class Dog extends Animal{
    public Dog(String name) {
        super(name);
//        System.out.println("Dog的构造方法");
    }
//    static {
//        System.out.println("Dog的静态代码块！");
//    }
//    {
//        System.out.println("Dog的非静态代码块！");
//    }
    public void barkWang() {
        System.out.println(this.name+"汪汪叫！");
    }
    public void eat() {
        System.out.println(this.name+"吃狗粮！");
    }
}
class Cat extends Animal{
    // …… 猫自己特有的属性
    public Cat(String name) {
        super(name);
    }
    public void barkMiao() {
        System.out.println(this.name+"喵喵喵！");
    }
}
public class Test {
    public static void main(String[] args) {
//        Dog dog1 = new Dog("小狗1");
//        Animal animal = dog1;
        //父类引用  引用了子类对象
        Animal animal = new Dog("小狗1");
        animal.eat();
//        Animal animal1 = new Animal("小狗2");
//        animal1.eat();
//        animal1.barkWang;//barkWang报错


    }
//    public static void main3(String[] args) {
//        Dog dog1 = new Dog("小狗1");
//        System.out.println("==================");
//        Dog dog2 = new Dog("小狗2");
//
//    }
//    public static void main2(String[] args) {
//        //假设只有Animal这一个类
//        Animal animal = new Animal("Animal");
//        System.out.println("=================");
//        Animal animal1 = new Animal("animal2");
//    }
//    public static void main1(String[] args) {
//        Dog dog = new Dog("旺财");
//        dog.eat();
//        dog.barkWang();
//        System.out.println("====================");
//
//        Cat cat = new Cat("团圆");
//        cat.eat();
//        cat.barkMiao();
//    }
}
